package com.qianyu.core.service.impl;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianyu.core.entity.bean.Game;
import com.qianyu.core.mapper.GameMapper;
import com.qianyu.core.service.GameService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements GameService {
    @Override
    public boolean saveGame(Game game) {
        if(validateArea(game.getAppid())){
            save(game);
        }
        return true;
    }

    private boolean validateArea(String appid){
        LambdaQueryWrapper<Game> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Game::getAppid,appid);
        return ObjUtil.isEmpty(baseMapper.selectOne(wrapper));
    }
}
